import openpyxl



def extract(filename):
    wb = openpyxl.load_workbook(filename)
    # sheetname = wb.get_sheet_names()
    ws = wb["查询报表"]

    ws_rows_len = len(list(ws.rows))    # 行数
    ws_col_len = len(list(ws.columns))  # 列数

    result = []

    columnList2 = ['AB','K']
    for x in columnList2:
        d = []
        column2 = ws[x]
        for c in range(len(column2)):
            d.append(column2[c].value)
        result.append(d)
    return result

def save(filename,result):
    wb = openpyxl.Workbook()
    ws = wb.active
    col = ['A','B']
    for c in range(len(col)):
        for r in range(len(result[c])):
            ws.cell(row=r+1,column=c+1,value=result[c][r])
    wb.save(filename)

if __name__ == "__main__":
    old_filename = r"C:\Users\tujuan\Desktop\7月故障周报\7.1-7.28\demo.xlsx"
    new_filename = r"C:\Users\tujuan\Desktop\7月故障周报\7.1-7.28\7.1-7.28(整理).xlsx"
    result = extract(old_filename)
    save(new_filename,result)
    print('Excel 创建成功！')